import time
from time import sleep
import os

from utils.PathUtil import BASE_PATH


# 串口 继电器
RESET_OPEN_CMD = 'A0 01 01 A2 '
RESET_CLOSE_CMD = 'A0 01 00 A1'


def exec_cmd(cmd):
    result = os.popen(cmd).read()
    return result


# 门锁 猫眼 按ok键，唤醒设备（15秒内必须有操作，否则又休眠）
def loca_wakeup_switch(relay):
    try:
        # com的继电器
        relay.sendMsg2(bytes.fromhex(RESET_OPEN_CMD))
        sleep(1.5)
        relay.sendMsg2(bytes.fromhex(RESET_CLOSE_CMD))
    except:
        pass
